import java.io.PrintStream;
import java.util.List;

public class RateComparator {
    private PrintStream printStream;
    private List<Hotel> hotelList;

    public RateComparator(PrintStream printStream, List<Hotel> hotelList) {
        this.printStream = printStream;
        this.hotelList = hotelList;
    }

    public void compare(String input) {
        InputParser inputParser = new InputParser(input);
        Hotel bestHotel = null;
        int bestValue = 1000000;
        for (Hotel hotel : hotelList) {
            if (valueCheck(inputParser, bestValue, hotel, bestHotel)){
                bestValue = reservationPrice(inputParser, hotel);
                bestHotel = hotel;
            }
        }
        printStream.println(bestHotel.name());
    }

    private boolean valueCheck(InputParser inputParser, int bestValue, Hotel hotel, Hotel bestHotel) {
        return bestValue > reservationPrice(inputParser, hotel) ||
               bestValue == reservationPrice(inputParser, hotel) &&
               bestHotel.rating() < hotel.rating();
    }

    private int reservationPrice(InputParser inputParser, Hotel hotel) {
        int value = 0;
        for (String day : inputParser.dayList()) {
            value += hotel.rate(inputParser.customerType(), day);
        }
        return value;
    }

}
